/** Biorhythmix
 * @author Vitaliy Lagutin
 * @version 1.0
 */

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.swing.BorderFactory;
import javax.swing.JPanel;

class PaintPanel extends JPanel {
	Biogui x;
	int nPoint = 61;
	Calendar cal = Calendar.getInstance();
		
	PaintPanel(int w, int h, Biogui x) {
		this.x = x;
		setOpaque(true);
		setBackground(Color.WHITE);
		setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
		setPreferredSize(new Dimension(w, h));		
	}
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		int height = getHeight();
		int width = getWidth();
		
		Graphics2D g2 =(Graphics2D) g;
		float[] dashPattern = {2.0f, 5.0f};
		g2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.CAP_SQUARE, 20.0f, dashPattern, 0));
		g.setColor(Color.LIGHT_GRAY);
		g.drawLine(0, height/4, width, height/4);
		g.drawLine(0, 3*height/4, width, 3*height/4);
		
		for (int x = 0; x < width; x = x + 10) {
			g.drawLine(x, 0, x, height);
		}
		g2.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1));
		
		g.setColor(Color.BLACK);
		g.drawLine(0, height/2, width, height/2);
		g.drawLine(width/2, 0, width/2, height);
		
		g.setFont(new Font("Monospace", Font.PLAIN, 11));
		g.drawString("0", width/2+1, height/2-1);
		g.drawString("-50%", width/2+2, 3*height/4-1);
		g.drawString("-100%", width/2+2, height-2);
		g.drawString("50%", width/2+1, height/4-1);
		g.drawString("100%", width/2+1, 11);
		
		DateFormat myformat = new SimpleDateFormat("dd.MM.yyyy");
		String date = myformat.format(new Date());
		g.drawString(date, width/2+1, height/2+10);
		cal.setTime(new Date());
		cal.add(Calendar.DATE, -30);
		String datepast = myformat.format(cal.getTime());
		g.drawString(datepast, 1, height/2+10);
		cal.setTime(new Date());
		cal.add(Calendar.DATE, 30);
		String datefuture = myformat.format(cal.getTime());
		g.drawString(datefuture, width-64, height/2+10);
			
		g.setColor(Color.RED);
		g.drawPolyline(x.xPoint, x.yPoint0, nPoint);
		g.setColor(Color.GREEN);
		g.drawPolyline(x.xPoint, x.yPoint1, nPoint);
		g.setColor(Color.BLUE);
		g.drawPolyline(x.xPoint, x.yPoint2, nPoint);
	}
}